package com.dragonfly.shutter.DAOIbatisImpls;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.dragonfly.shutter.DAOs.UserDAO;
import com.dragonfly.shutter.beans.RegisterBean;
import com.dragonfly.shutter.beans.UserBrief;
import com.dragonfly.shutter.beans.UserDetail;
import com.dragonfly.shutter.beans.UserLogin;
/**
 * UserDAO 的实现
 * @author 赵洁琼
 *
 */
public class UserDAOIbatisImpl extends SqlMapClientDaoSupport implements UserDAO {

	public Integer insertUser(UserDetail user) {
		return (Integer) this.getSqlMapClientTemplate().insert("insertUser", user);
	}

	public int updateFlagLogin(UserDetail userDetail) {
		return this.getSqlMapClientTemplate().update("updateFlagLogin", userDetail);
	}

	public int updateFlagUpload(UserDetail userDetail) {
		return this.getSqlMapClientTemplate().update("updateFlagUpload", userDetail);
	}

	public int updatePassword(UserDetail userDetail) {
		return this.getSqlMapClientTemplate().update("updatePassword", userDetail);		
	}

	@SuppressWarnings("unchecked")
	public int updateScore(Integer userID, Integer points) {
		Map map = new HashMap();
		map.put("userID", userID);
		map.put("points", points);
		
		return this.getSqlMapClientTemplate().update("updateScore", map);		
	}

	public int updateUser(UserDetail userDetail) {
		return this.getSqlMapClientTemplate().update("updateUser", userDetail);		
	}

	@SuppressWarnings("unchecked")
	public List<UserBrief> selectPagedUserBriefInfo(String userName,
			Integer minRow, Integer maxRow) {
		Map map = new HashMap();
		map.put("userName", userName);
		map.put("minRow", minRow);
		map.put("maxRow", maxRow);
		
		return this.getSqlMapClientTemplate().queryForList("selectPagedUserBriefInfo", map);
	}

	public UserBrief selectUserBriefInfoByUserId(Integer usrID) {
		return (UserBrief) this.getSqlMapClientTemplate().queryForObject("selectUserBriefInfoByUserId", usrID);
	}

	public UserLogin selectLoginInfoByEmail(String email) {
		return (UserLogin) this.getSqlMapClientTemplate().queryForObject("selectLoginInfoByEmail", email);
	}

	public Integer selectUserCountByUserName(String userName) {
		return (Integer) this.getSqlMapClientTemplate().queryForObject("selectUserCountByUserName", userName);
	}

	public Integer insertNewRegisterUser(UserLogin userLogin) {
		return (Integer) this.getSqlMapClientTemplate().insert("insertNewRegisterUser", userLogin);
	}

	public Integer insertRegisterBean(RegisterBean registerBean) {
		return (Integer) this.getSqlMapClientTemplate().insert("insertRegisterBean", registerBean);
	}

	public UserDetail selectUserByEmail(String email) {
		return (UserDetail) this.getSqlMapClientTemplate().queryForObject("selectUserByEmail", email);
	}

	public UserDetail selectUserByUserId(Integer userID) {
		return (UserDetail) this.getSqlMapClientTemplate().queryForObject("selectUserByUserId", userID);
	}

	public Integer updateFlagActive(UserDetail user) {
		return this.getSqlMapClientTemplate().update("updateFlagActive", user);
	}

	@Override
	public Integer selectUserPoint(Integer userID) {
		return (Integer) this.getSqlMapClientTemplate().queryForObject("selectUserPoint", userID);
	}
}
